#ifndef __XS_MSGQUE_H__
#define __XS_MSGQUE_H__

#ifdef __cplusplus
extern "C"{
#endif

#include "xs_linux.h"

#ifndef TRUE
#define TRUE    (1 == 1)
#define FLASE   (0 == 1)
#endif


#define OS_WRAP_MAX_TASKS  	50
#define OS_WRAP_MAX_QUEUES 	(OS_WRAP_MAX_TASKS * 2)
#define OS_WRAP_MAX_SEMS   	(OS_WRAP_MAX_TASKS * 10)
#define OS_NAME_MAX_LEN    		256



typedef unsigned long xs_queid;
typedef unsigned long xs_semid;

typedef void * xs_message;
typedef void * (*t_malloc_handler)(unsigned long size);
typedef void (*t_free_handler)(void *mem_p);


struct __xs_msg_block__{
    struct __xs_msg_block__ *nextp;
    xs_message   msg;
    unsigned short msglen;
};
typedef struct __xs_msg_block__  xs_msg_block;


struct __queue_block_control__{
    char name[OS_NAME_MAX_LEN + 1];
    xs_semid semid;
    xs_pthread_mutex_t qmutex;
    xs_msg_block *firstp;
    xs_msg_block *lastp;

};
typedef struct __queue_block_control__ xs_qcb;

struct __sem_control_block__{
    char name[OS_NAME_MAX_LEN + 1];
    xs_semid semid;
    xs_pthread_cond_t cond_var;
    xs_pthread_mutex_t sem_mutex;
    int sem_count;
};
typedef struct __sem_control_block__ xs_scb;


struct __queue_data_control__{
    xs_pthread_mutex_t g_mutex;
    int que_num;
    xs_qcb   qcb_array[OS_WRAP_MAX_QUEUES];
    xs_pthread_mutex_t g_que_mutex;
    int semnum;
    xs_scb   scb_array[OS_WRAP_MAX_SEMS];
    xs_pthread_mutex_t g_sem_mutex;
};
typedef struct __queue_data_control__ t_queue_global;

typedef enum
{
    __message_success__ = 0,
    __message_unsuccess__,
    __message_id_not_exsit__,

} xs_message_ret;

extern int xs_msgque_init();
extern unsigned long xs_msgque_create(char *p_name);
extern unsigned short xs_msgque_send(unsigned long qid,void *msg,unsigned short msglen);
extern unsigned short xs_msgque_recv(unsigned long qid,void **msg,unsigned short *msglen);


int xs_message_queue_test();
	
#ifdef __cplusplus
}
#endif //endof __

#endif
